home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / UPPERTEXT / Patches.c < prev    next >
C/C++ Source or Header  |  2000-06-23  |  6KB  |  189 lines

  1. // Source Code generated by PatchMaker 1.0
  2. // a sick idea by Paul Baxter
  3.  
  4. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  5.     #error Sorry Can't do that
  6. #endif
  7.  
  8. #include <MixedMode.h>
  9. #include <Appearance.h>
  10. #include <SpeechSynthesis.h>
  11.  
  12. // enums for routinedescriptor
  13. enum {
  14.     upp_StdTextProcInfo_0_0 = kPascalStackBased
  15.         |    STACK_ROUTINE_PARAMETER(1,kTwoByteCode)
  16.         |    STACK_ROUTINE_PARAMETER(2,kFourByteCode)
  17.         |    STACK_ROUTINE_PARAMETER(3,kFourByteCode)
  18.         |    STACK_ROUTINE_PARAMETER(4,kFourByteCode),
  19.     upp_StdTextProcInfo_1_0 = kPascalStackBased
  20.         |    STACK_ROUTINE_PARAMETER(1,kTwoByteCode)
  21.         |    STACK_ROUTINE_PARAMETER(2,kFourByteCode)
  22.         |    STACK_ROUTINE_PARAMETER(3,kFourByteCode)
  23.         |    STACK_ROUTINE_PARAMETER(4,kFourByteCode),
  24.     uppPatcExtraInfo
  25. };
  26.  
  27. // Function Prototypes
  28. extern pascal void my_StdText_0_0Patch(short param1, long param2, long param3, long param4);
  29. extern pascal void my_StdText_1_0Patch(short param1, long param2, long param3, long param4);
  30. pascal void my_StdTextPatch(short param1, long param2, long param3, long param4);
  31.  
  32.  
  33. // Globals to hold original routine descriptors
  34. RoutineDescriptorPtr gOriginal_StdText_0_0 = nil;
  35. RoutineDescriptorPtr gOriginal_StdText_1_0 = nil;
  36.  
  37. #define EnterCodeResource()
  38. #define ExitCodeResource()
  39.  
  40.  
  41. // Tell MetroWerks the procInfo for main
  42. ProcInfoType __procinfo =  kPascalStackBased;
  43. pascal void main(void)
  44. {
  45.     RoutineDescriptorPtr originaldesc, newdesc, unImplimentedTrapAddr;
  46.     UInt32 size;
  47.     UInt16 index;
  48.     THz theZone;
  49.  
  50.     // get globals
  51.     EnterCodeResource();
  52.     // detach ourselves
  53.     DetachResource(Get1Resource('INIT', 0));
  54.  
  55.     // make sure we are in the system heap
  56.     theZone = GetZone();
  57.     SetZone(SystemZone());
  58.     
  59.     unImplimentedTrapAddr = NGetTrapAddress(_Unimplemented, (_Unimplemented & 0x0800) ? ToolTrap : OSTrap);
  60.  
  61.     originaldesc = NGetTrapAddress(_StdText, (_StdText & 0x0800) ? ToolTrap : OSTrap);
  62.     if (originaldesc != unImplimentedTrapAddr) {
  63.         if (originaldesc->goMixedModeTrap != _MixedModeMagic) {
  64.             // Trap is 68K
  65.             size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * 1);
  66.             // allocate new descriptor
  67.             newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
  68.             if (!newdesc) {
  69.                 Debugger();
  70.                 return;
  71.             }
  72.             // set fields of routine decscriptor
  73.             newdesc->goMixedModeTrap = _MixedModeMagic;
  74.             newdesc->version = 7;
  75.             newdesc->routineDescriptorFlags = 0;
  76.             newdesc->reserved1 = 0;
  77.             newdesc->reserved2 = 0;
  78.             newdesc->selectorInfo = 0;
  79.             newdesc->routineCount = 1;
  80.             index = 0;
  81.             gOriginal_StdText_0_0 = originaldesc;
  82.             newdesc->routineRecords[index].procInfo = upp_StdTextProcInfo_0_0;
  83.             newdesc->routineRecords[index].reserved1 = 0;
  84.             newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  85.             newdesc->routineRecords[index].routineFlags = 0;
  86.             newdesc->routineRecords[index].procDescriptor = (ProcPtr)my_StdText_0_0Patch;
  87.             newdesc->routineRecords[index].reserved2 = 0;
  88.             newdesc->routineRecords[index].selector = 0;
  89.             index = 1;
  90.             gOriginal_StdText_1_0 = originaldesc;
  91.             newdesc->routineRecords[index].procInfo = upp_StdTextProcInfo_1_0;
  92.             newdesc->routineRecords[index].reserved1 = 0;
  93.             newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  94.             newdesc->routineRecords[index].routineFlags = 0;
  95.             newdesc->routineRecords[index].procDescriptor = (ProcPtr)my_StdText_1_0Patch;
  96.             newdesc->routineRecords[index].reserved2 = 0;
  97.             newdesc->routineRecords[index].selector = 0;
  98.         }
  99.         else {
  100.             // Trap is PPC
  101.             size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * originaldesc->routineCount);
  102.             newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
  103.             if (!newdesc) {
  104.                 DebugStr("\pFailed to allocate RoutineDescriptor");
  105.                 return;
  106.             }
  107.             BlockMoveData(originaldesc, newdesc, size);
  108.             for (index = 0; index <= newdesc->routineCount; index++) {
  109.                 if ((originaldesc->routineRecords[index].selector == 0) &&
  110.                 (originaldesc->routineRecords[index].ISA == 0) && (originaldesc->routineRecords[index].procInfo == upp_StdTextProcInfo_0_0)) {
  111.                     gOriginal_StdText_0_0= NewRoutineDescriptor(originaldesc->routineRecords[index].procDescriptor,
  112.                                 upp_StdTextProcInfo_0_0, originaldesc->routineRecords[index].ISA);
  113.                     newdesc->routineRecords[index].procDescriptor = (ProcPtr)my_StdText_0_0Patch;
  114.                     newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  115.                     continue;
  116.                 }
  117.                 if ((originaldesc->routineRecords[index].selector == 0) &&
  118.                 (originaldesc->routineRecords[index].ISA == 1) && (originaldesc->routineRecords[index].procInfo == upp_StdTextProcInfo_1_0)) {
  119.                     gOriginal_StdText_1_0= NewRoutineDescriptor(originaldesc->routineRecords[index].procDescriptor,
  120.                                 upp_StdTextProcInfo_1_0, originaldesc->routineRecords[index].ISA);
  121.                     newdesc->routineRecords[index].procDescriptor = (ProcPtr)my_StdText_1_0Patch;
  122.                     newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
  123.                     continue;
  124.                 }
  125.             }
  126.         }
  127.         NSetTrapAddress((UniversalProcPtr) newdesc, _StdText, (_StdText & 0x0800) ? ToolTrap : OSTrap);
  128.     }
  129.  
  130.     // restore to original heap
  131.     SetZone(theZone);
  132.     // restore globals
  133.     ExitCodeResource();
  134. }
  135.  
  136.  
  137. pascal void my_StdText_0_0Patch(short param1, long param2, long param3, long param4)
  138. {
  139.     // Get globals
  140.     EnterCodeResource();
  141.  
  142.     my_StdTextPatch( param1, param2, param3, param4);
  143.  
  144.     // Release globals
  145.     ExitCodeResource();
  146. }
  147.  
  148. pascal void my_StdText_1_0Patch(short param1, long param2, long param3, long param4)
  149. {
  150.     // Get globals
  151.     EnterCodeResource();
  152.  
  153.     my_StdTextPatch( param1, param2, param3, param4);
  154.  
  155.     // Release globals
  156.     ExitCodeResource();
  157. }
  158.  
  159. pascal void my_StdTextPatch(short param1, long param2, long param3, long param4)
  160. {
  161.     SInt16 count, count1;
  162.     Ptr theText = (Ptr)param2;
  163.     char temp;
  164.  
  165.     // Get globals
  166.     EnterCodeResource();
  167.  
  168.     for(count=0; count < param1; count++) {
  169.         if (theText[count] >= 'a' && theText[count] <= 'z')
  170.             theText[count] = (theText[count] - 'a') + 'A';
  171.     }
  172.  
  173.     for(count=0; count < param1-1; count++) {
  174.         for(count1=count+1; count1 < param1; count1++) {
  175.             if (theText[count]  <= theText[count1]) {
  176.                 temp = theText[count];
  177.                 theText[count] = theText[count1];
  178.                 theText[count1] = temp;
  179.             }
  180.         }
  181.     }
  182.     
  183.     CALL_FOUR_PARAMETER_UPP( gOriginal_StdText_1_0, upp_StdTextProcInfo_1_0, param1, param2, param3, param4);
  184.  
  185.     // Release globals
  186.     ExitCodeResource();
  187. }
  188.  
  189.